package cn.ekuma.util;

import java.util.Random;

public class RandomWordGenerator {
	public static final String NUMBER="0123456789";
	public static final String NUMBER_UP="零壹贰叁肆伍陆柒捌玖";
	public static final String ASSIC="abcdefghijklmnopqrstuvwxyz";
	public static final String ASSIC_UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	public static final String ALL=NUMBER+ASSIC+ASSIC_UP;
	
	public static final String PATTERN_ALL="^[A-Za-z0-9]+$";
	
     public static class Config {
        	private int len;
        	private String randomWord;
        	private String like;
        	private String exceptPattern;
			
        	
        	public Config(int len) {
				this(len,ALL);
			}


			public Config(int len, String randomWord) {
				this(len,randomWord,null);
				
			}


			public Config(int len, String randomWord, String like) {
				this(len,randomWord,like,null);
			}


			public Config(int len, String randomWord, String like,
					String exceptPattern) {
				super();
				this.len = len;
				this.randomWord = randomWord;
				this.like = like;
				this.exceptPattern = exceptPattern;
			}	
     }
     
     
     public static RandomWordGenerator instance(int len){
    	 return new RandomWordGenerator(new Config(len));
     }
     
     public static RandomWordGenerator instance(int len, String randomWord){
    	 return new RandomWordGenerator(new Config(len,randomWord));
     } 
        
     Config config;    
     Random random;  
     
    public RandomWordGenerator(Config config) {
		super();
		this.config = config;
		random=new Random();
	}


	public String random(){
		StringBuilder builder=new StringBuilder();
		for(int i=0;i<config.len;i++)
			builder.append(random(i));
    	return builder.toString();
    }
    
    
    private char random(int position){
    	return config.randomWord.charAt(random.nextInt(config.randomWord.length()));
    }
        
}
